#!/usr/bin/env python
# System dependent functions

import sys
import os

from configs import config
from misc import convert_to_bmp
from logger import logger

if sys.platform == 'win32':
    import ctypes
    import win32con
    user32 = ctypes.windll.user32
else:
    pass  #Linux support

# Set as wallpaper
def set_wallpaper(filepath):
    """Set image 'filepath' as Wallpaper"""
    if sys.platform == 'win32':
        bmpfile = os.path.join(config["OUTPUT_PATH"], "wallpaper.bmp")
        logger.info("BMP output file: " + bmpfile)

        convert_to_bmp(filepath, bmpfile)

        user32.SystemParametersInfoA(win32con.SPI_SETDESKWALLPAPER, 0, bmpfile , win32con.SPIF_UPDATEINIFILE | win32con.SPIF_SENDWININICHANGE)
    else:
        logger.error("Not implemented.")

def get_screen_resolution():
    """Return (width, height) of screen"""
    if sys.platform == 'win32':
        return (user32.GetSystemMetrics(0), user32.GetSystemMetrics(1))
    else:
        logger.error("Not implemented.")

def msgbox(title, msg):
    """Display a simple message box with title"""
    if sys.platform == 'win32':
        MessageBox = user32.MessageBoxA
        MessageBox(None, msg, title, 0)
    else:
        logger.error("Not implemented.")
